﻿<template>
  <ul class="vertical-menu">
    <li class="menu-item" v-for="(menu, index) in menus" :key="index">
       <router-link v-text="menu.title" :to="menu.link"  v-if="menu.hasChild==false"></router-link>
       <h2 @click="onShowToggle(menu, index)" v-if="menu.hasChild==true"> 
         <div v-text="menu.title"></div>
         <em v-show="menu.hasChild" :class="{'actived': menu.isShow}"></em> 
      </h2>
      <ul class="sub-menu" v-show="menu.isShow" v-if="menu.hasChild==true">
        <router-link tag="li" class="sub-menu-item" v-for="(item, index) in menu.childs" :key="index" :to="item.link" v-text="item.title">
        </router-link>
      </ul>
    </li>
  </ul>
</template>

<script>
  export default {
    data() {
      return {
        isclick: false
      }
    },
    props: {
      menus: [Array]
    },
    methods: {
      onShowToggle(menu) {
        menu.isShow = !menu.isShow
      }
    }
  }
</script>

<style lang="scss" scoped>
  $fontSize: 14px;
  .vertical-menu {
    width: 140px;
    color: #444444;
    border: 1px solid #DDDDDD;
    background-color: #fff;
  }

  .menu-item {
    a {
      border-bottom: 1px solid #DDDDDD;
      padding-left: 20px;
      height: 38px;
      line-height: 38px;
      font-size: $fontSize;
      font-weight: 500;
      display: block;
      cursor: pointer;
    }
    h2 {
      border-bottom: 1px solid #DDDDDD;
      padding-left: 20px;
      height: 38px;
      line-height: 38px;
      font-size: $fontSize;
      font-weight: 500;
      cursor: pointer;
      div {
        min-width: 65px;
        margin-right: 17px;
        display: inline-block;
      }
      em {
        background: url('../assets/arrow.png') no-repeat 0 0;
        width: 18px;
        height: 9px;
        display: inline-block;
        transition: all .2s;
        transform: rotate(180deg) translateY(2px);
        &.actived {
          transform: rotate(0) translateY(2px);
        }
      }
    }
  }
  .sub-menu {
    transition: all .3s ealse;
  }

  .sub-menu-item {
    padding-left: 20px;
    height: 38px;
    font-size: 12px;
    line-height: 38px;
    cursor: pointer;
    border-bottom: 1px solid #DDDDDD;
  }

  .router-link-active {
    background-color: #F00384;
    color: #fff;
  }
</style>